<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="yes" />
<title><?=$da['title']?></title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet" type="text/css" href="webmain/css/cssm.css">
<link rel="stylesheet" type="text/css" href="webmain/css/aui.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jsm.js"></script>

<script>
var deptarrs=[],userarr=[],changetype='';
function initbody(){
	changetype = js.request('changetype');
	mainobj=$('#maindiv');
	if(changetype==''){
		$('.xuandiv').hide();
	}else{
		$('#bottombtn').show();
		$('#bottombtns').show();
	}
	if(js.request('stype')!='1'){
		$('#headersss').show();
	}
	var s = js.getoption('xinhusystemdept');
	if(s!=''){
		getlistla(s);
	}else{
		loaddata();
	}
}
function getlistla(s){
	mainobj.html('');
	deptarrs = js.decode(s);
	s= js.getoption('xinhusystemuser');
	if(s!='')userarr=js.decode(s);
	showlistss(0,0,'maindiv');
	showlistss(1,1,'dept1');
}
function loaddata(){
	js.ajax('dept','data',{},function(ret){
		js.setoption('xinhusystemdept', ret.deptjson);
		js.setoption('xinhusystemuser', ret.userjson);
		getlistla(ret.deptjson);
	});
}
function showlistss(pid, oi, shid){
	var a=deptarrs;
	var s='',i,len=a.length,type='checkbox';
	var hw=24;
	if(changetype.indexOf('check')==-1)type='radio';
	for(i=0;i<len;i++){
		if(a[i].pid==pid){
			s+='<div class="index_list listsss" style="padding-left:'+(hw*oi+10)+'px">';
			s+='	<div onclick="clickshowna('+i+', '+oi+')"  class="index_title"><img width='+hw+' height='+hw+' src="images/files.png" align="absmiddle">&nbsp;'+a[i].name+'</div>';
			if(changetype.indexOf('dept')>-1)s+='<span class="right"><input id="box_d_'+a[i].id+'" onclick="xuandeptuser(\''+a[i].id+'\',\''+a[i].name+'\',\'d\', this)" type="'+type+'" name="allinptsss" class="checkbox"></span>';
			s+='</div>';
			s+='<span show="false" id="dept'+a[i].id+'"></span>';
		}
	}
	a=userarr;
	len=a.length;
	for(i=0;i<len;i++){
		if(a[i].deptid==pid){
			s+='<div class="index_list listsss" style="padding-left:'+(hw*oi+10)+'px">';
			s+='	<div class="index_title" onclick="xuanuser('+i+')"><img width='+hw+' height='+hw+' src="'+a[i].face+'" align="absmiddle">&nbsp;'+a[i].name+'('+a[i].ranking+')</div>';
			if(changetype.indexOf('user')>-1)s+='<span class="right"><input id="box_u_'+a[i].id+'" onclick="xuandeptuser(\''+a[i].id+'\',\''+a[i].name+'\',\'u\', this)" name="allinptsss" type="'+type+'" class="checkbox"></span>';
			s+='</div>';
		}
	}
	$('#'+shid+'').html(s);
}
function clickshowna(xu,oi){
	var a = deptarrs[xu];
	var o1= $('#dept'+a.id+'');
	var lx= o1.attr('show');
	if(lx=='false'){
		showlistss(a.id,oi+1,'dept'+a.id+'');
		o1.attr('show','true');
	}else{
		o1.toggle();
	}
}
function xuandeptuser(id,na,lx,o2){
	var o1 = $('.xuandiv');
	if(changetype.indexOf('check')<0)o1.html('');
	var ssid = 'show_'+lx+'_'+id+'';
	if(!o2.checked){
		$('#'+ssid+'').remove();
		return;
	}
	if(lx=='d' && changetype.indexOf('dept')<0)return;
	if(lx=='u' && changetype.indexOf('user')<0)return;
	
	var s = '<span id="'+ssid+'"><i>'+id+'</i><u>'+lx+'</u><a>'+na+'</a>'+na+'&nbsp;<font onclick="removeuid(\''+id+'\',\''+lx+'\')">×</font></span>';
	o1.append(s);
}
function xuanuser(oi){
	return;
	if(changetype!='')return;
	var d = userarr[oi];
	js.location('userinfor.html?uid='+d.id+'&'+jm.encrypt(d.name)+'');
}
function removeuid(id,lx){
	var ssid = 'show_'+lx+'_'+id+'';
	$('#'+ssid+'').remove();
	get('box_'+lx+'_'+id+'').checked=false;
}

function searchcard(){
}
function cancel(){
	try{parent.changecancel();}catch(e){}
	js.backla();
}
function okla(){
	var s = '',sid='',sna='';
	var o=$('.xuandiv').find('i');
	var o1=$('.xuandiv').find('a');
	var o2=$('.xuandiv').find('u');
	var s1='',s2='',lx='';
	var xubo = false;
	if(changetype.indexOf('dept')>-1 && changetype.indexOf('user')>-1)xubo=true;
	for(var i=0;i<o.length;i++){
		s1 = $(o[i]).text();
		s2 = $(o1[i]).text();
		lx = $(o2[i]).text();
		if(xubo)s1=''+lx+''+s1+'';
		sid+=','+s1;
		sna+=','+s2;
	}
	if(sid!=''){
		sid=sid.substr(1);
		sna=sna.substr(1);
	}
	var calb = js.request('callback');
	try{if(calb!='')parent[calb](sna,sid);}catch(e){}
	try{parent.changeok(sna,sid);}catch(e){}
	var evst=js.request('event');
	if(evst!='')js.sendevent('changeuser', evst, {name:sna,nameid:sid});
	cancel();
}
function backshow(){
	if(changetype!=''){
		cancel();
		return;
	}
	js.gotoback();
}
</script>
<style>
*{font-size:14px}
.index_list{
	padding:10px 5px;border-bottom:1px #eeeeee solid;
	background:white;
}
.index_list:not(.no_access):active{ background:#C1E8F2}
.checkbox{height:16px;width:16px;}
.xuandiv{padding:10px;background:white;border-bottom:1px #eeeeee solid;line-height:30px;}
.xuandiv span{padding:2px 5px;background-color:#3FBFC2;color:white;margin:5px}
.xuandiv i,.xuandiv a,.xuandiv u{display:none}
.listsss{position:relative}
.listsss .right{top:10px; position:absolute; right:10px}
.listsss img{height:20px;width:20px}
#bottombtn{position:fixed;bottom:0px; background-color:white;width:100%;text-align:right;overflow:hidden;border-top:1px #cccccc solid}
#bottombtns{height:50px;overflow:hidden;display:none}
.btns{padding:0px 10px;margin:10px 0px;height:30px;line-height:30px; background-color:#1abc9c;border:none;color:white;font-size:14px}
.btns:active{ background-color:#099B7E}
</style>
</head>
<body class="mbody">
	<div id="headersss" style="display:none">
	<div class="header">
		<span class="back" onclick="cancel()"><img src="images/back.png"></span>
		<span onclick="location.reload();">请选择</span>
	</div>
	<div class="blank46"></div>
	</div>

	<div class="xuandiv"></div>
	<div id="maindiv"></div>
	
	<div id="bottombtns"></div>
	<div id="bottombtn">
		<button onclick="loaddata()" style="background-color:#888888" class="btns" type="button">刷新数据</button>&nbsp; &nbsp; 
		<button onclick="cancel()" class="btns" type="button">取消</button>&nbsp; &nbsp; 
		<button onclick="okla()" class="btns" type="button">确定</button>&nbsp; &nbsp;
	</div>
</body>
</html>